#!/usr/bin/python
# -*- coding: utf-8 -*-

import unittest

# A cat class
class MyCat(object):
    def meow(self):
        return "My cat meows."

# A car class 
class MyCar(object):    
    def vroom(self):
        return "My car vrooms."

# interface of objects that make noise   
class INoisyObject(object):
    def make_noise(self):
        pass

# cat adapter to implement the INoisyObject interface
class CatAdapter(INoisyObject):
    def __init__(self, o_cat):
        INoisyObject.__init__(self)
        self.__o_cat = o_cat
        
    def make_noise(self):
        return self.__o_cat.meow()
    
# car adapter to implement the INoisyObject interface
class CarAdapter(INoisyObject):
    def __init__(self, o_car):
        INoisyObject.__init__(self)
        self.__o_car = o_car
        
    def make_noise(self):
        return self.__o_car.vroom()
        

class TestCase(unittest.TestCase):        
    def test_adapter(self):
        """Adapter creation"""
        # create a cat adapter
        my_cat_adapter = CatAdapter(MyCat())
        # create car adapter
        my_car_adapter = CarAdapter(MyCar())
        
        self.assertEqual(my_cat_adapter.make_noise(), "My cat meows.")
        self.assertEqual(my_car_adapter.make_noise(), "My car vrooms.")
    
    def test_class_inheritance(self):
        """Class inheritance test"""
        # create a cat adapter
        my_cat_adapter = CatAdapter(MyCat())
        
        # my_cat_adapter is a instance of CatAdapter...
        self.assertTrue(isinstance(my_cat_adapter, CatAdapter))
        # but not of
        self.assertFalse(isinstance(my_cat_adapter, MyCar))
        
if __name__ == '__main__':
    unittest.main()
            
        

    